<template>
  <base-layout>
    <template #searchPanel>
      <search-panel
        :addPer="'asset:save'"
        :selectPer="'asset.query'"
        :excelPer="'admin'"
        addTitle="新增资产"
        @insert="add"
        @search="search"
        :showSearchButton="true"
        :showExportButton="true"
        :showAddButton="true"
        @export="handleDataExport('Asset', '固定资产')"
      >

        <job-shop v-model="form.storeId" placeholder="所属门店" />
        <el-select clearable style="width: 200px" v-model="form.assetType" placeholder="资产类型">
          <el-option
            v-for="item in assetTypeOptios['资产类型']"
            :key="item.id"
            :value="item.value"
            :label="item.text"
          />
        </el-select>
        <el-input v-model="form.assetNameAndCode" clearable placeholder="资产编号" style="width: 200px" />
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :width="160"
      >
        <template #action="{row}">
          <i class="el-icon-edit" title="编辑" style="cursor: pointer;" v-permission="'asset.edit'" @click="handleDataUpdateEdit(row)"></i>
          <i class="el-icon-delete" title="删除" style="color:red; margin-left: 20px;cursor: pointer" v-permission="'asset.del'" @click="handleDataDelete(row)"></i>
        </template>
      </data-table>
    </template>
  </base-layout>
</template>
<script>
import {
  dataList,
  dicts,
  details,
  addData,
  updateData,
  deleteData,
} from  '@/api/after-sale/finance/assets'
import {getDict, exportExcel} from '@/utils/index'
import baseMixin from '@/mixins/base';
export default {
  mixins: [
    baseMixin({
      findData: dataList,
      addData: addData,
      deleteData: deleteData,
      dataName: ['content', 'totalRecords'],
      isAdd: false,
      findDataById: details,
      updateData: updateData,
      idName: 'id'
    })
  ],
  data() {
    return {
      authConfig: {
        query: 'asset:page',
        add: 'asset:save',
        edit: 'asset:update',
        del: 'asset:del',
      },
      tableColumnAttributes: [
        { name: '所属门店', value: 'storeName', type: 'text' },
        { name: '资产名称', value: 'assetName', type: 'text' },
        { name: '资产编号', value: 'assetCode', type: 'text' },
        { name: '资产类型', value: 'assetType', type: 'text' },
        { name: '资产单价', value: 'assetPrice', type: 'text' },
        { name: '资产数量', value: 'assetNum', type: 'text' },
        { name: '资产总金额', value: 'assetAmount', type: 'text' },
        { name: '存放位置', value: 'address', type: 'text' },
        { name: '备注', value: 'remark', type: 'text' },
        { name: '录入时间', value: 'createTime', type: 'text' },
      ],
      assetTypeOptios: [],
      form: {
        storeId: '',
        assetType: '',
        assetNameAndCode: ''
      }
    }
  },
  async created() {
    this.assetTypeOptios = getDict(['资产类型']);
  },
  methods:{
    search() {
      this.searchOptions = this.form
      this.currentPage = 1
      this.setTableData()
    },
    add(){
      this.$router.push({ path: '/financialflow/addAsset' })
    },
    handleDataUpdateEdit(row){
      this.$router.push({
        path:'/financialflow/editAsset',
        query:{
          id: row.id,
        }
      })
    },
  }
}
</script>
